var a = getApp();

Page({
    data: {
        language: "",
        id: "",
        goodsList: [],
        total_page: 0,
        isLoadMore: !0,
        page: 1,
        brandTit: "",
        brandLogo: "",
        desc: "",
        scribing_show: 0,
        market_price: ""
    },
    onLoad: function(a) {
        a.id && this.setData({
            id: a.id
        }), this._getData(), this._getInfo();
        var t = wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show && 1 == wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show ? 1 : 0, o = wx.getStorageSync("yz_basic_info").lang.goods, e = o ? o.market_price : "原价";
        console.log(o, o.market_price), this.setData({
            scribing_show: t,
            market_price: e
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {
        return {
            path: "/packageB/member/goods/GoodsBrand/GoodsBrand?id=" + this.data.id
        };
    },
    _getData: function() {
        var t = this, o = a.getNetAddresss("goods.brand.get-brand-goods");
        o += "&id=" + this.data.id, a._getNetWork({
            url: o,
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    t.setData({
                        goodsList: o.data.goods.data,
                        total_page: o.data.goods.total
                    });
                    for (var e = 0; e < o.data.goods.data.length; e++) try {
                        0 == Number(o.data.goods.data[e].market_price) ? t.data.goodsList[e].notMarket_price = 0 : t.data.goodsList[e].notMarket_price = 1, 
                        t.setData({
                            goodsList: t.data.goodsList
                        });
                    } catch (a) {
                        console.log(a);
                    }
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _getInfo: function() {
        var t = this, o = a.getNetAddresss("goods.brand.get-brand-detail");
        o += "&id=" + this.data.id, a._getNetWork({
            url: o,
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    var e = o.data.desc.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block"');
                    t.setData({
                        brandTit: o.data.name,
                        brandLogo: o.data.logo,
                        desc: e
                    });
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (!(this.data.page >= this.data.total_page)) {
            t.setData({
                page: this.data.page + 1
            });
            var o = a.getNetAddresss("goods.brand.get-brand-goods");
            o += "&id=" + this.data.id, o += "&page=" + this.data.page, a._getNetWork({
                url: o,
                success: function(a) {
                    var o = a.data;
                    if (1 == o.result) {
                        var e = o.data.goods.data;
                        if (e.length > 0) {
                            var s = t.data.goodsList;
                            t.setData({
                                goodsList: s.concat(e)
                            });
                        } else t.setData({
                            isLoadMore: !1
                        });
                    } else t.setData({
                        page: t.data.page - 1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    gotoDetail: function(a) {
        var t = a.currentTarget.dataset.goodsid;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    }
});